package com.ruoyi.monitor.controller;

import java.util.List;
import java.util.ArrayList;
import java.util.stream.Collectors;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.monitor.domain.MonitorRetrievalRequest;
import com.ruoyi.monitor.service.IMonitorRetrievalRequestService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.SecurityUtils;
import java.util.Date;

/**
 * 监控调取申请Controller
 * 
 * @author lh
 * @date 2025-04-16
 */
@RestController
@RequestMapping("/monitor/request")
public class MonitorRetrievalRequestController extends BaseController
{
    @Autowired
    private IMonitorRetrievalRequestService monitorRetrievalRequestService;

    /**
     * 查询监控调取申请列表
     */
    @PreAuthorize("@ss.hasPermi('monitor:request:list')")
    @GetMapping("/list")
    public TableDataInfo list(MonitorRetrievalRequest monitorRetrievalRequest)
    {
        startPage();
        List<MonitorRetrievalRequest> list = monitorRetrievalRequestService.selectMonitorRetrievalRequestList(monitorRetrievalRequest);
        return getDataTable(list);
    }

    /**
     * 导出监控调取申请列表
     */
    @PreAuthorize("@ss.hasPermi('monitor:request:export')")
    @Log(title = "监控调取申请", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MonitorRetrievalRequest monitorRetrievalRequest)
    {
        List<MonitorRetrievalRequest> list = monitorRetrievalRequestService.selectMonitorRetrievalRequestList(monitorRetrievalRequest);
        ExcelUtil<MonitorRetrievalRequest> util = new ExcelUtil<MonitorRetrievalRequest>(MonitorRetrievalRequest.class);
        util.exportExcel(response, list, "监控调取申请数据");
    }

    /**
     * 获取监控调取申请详细信息
     */
    @PreAuthorize("@ss.hasPermi('monitor:request:query')")
    @GetMapping(value = "/{requestId}")
    public AjaxResult getInfo(@PathVariable("requestId") Long requestId)
    {
        return success(monitorRetrievalRequestService.selectMonitorRetrievalRequestByRequestId(requestId));
    }

    /**
     * 新增监控调取申请
     */
    @PreAuthorize("@ss.hasPermi('monitor:request:add')")
    @Log(title = "监控调取申请", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MonitorRetrievalRequest monitorRetrievalRequest)
    {
        return toAjax(monitorRetrievalRequestService.insertMonitorRetrievalRequest(monitorRetrievalRequest));
    }

    /**
     * 修改监控调取申请
     */
    @PreAuthorize("@ss.hasPermi('monitor:request:edit')")
    @Log(title = "监控调取申请", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MonitorRetrievalRequest monitorRetrievalRequest)
    {
        return toAjax(monitorRetrievalRequestService.updateMonitorRetrievalRequest(monitorRetrievalRequest));
    }

    /**
     * 删除监控调取申请
     */
    @PreAuthorize("@ss.hasPermi('monitor:request:remove')")
    @Log(title = "监控调取申请", businessType = BusinessType.DELETE)
	@DeleteMapping("/{requestIds}")
    public AjaxResult remove(@PathVariable Long[] requestIds)
    {
        return toAjax(monitorRetrievalRequestService.deleteMonitorRetrievalRequestByRequestIds(requestIds));
    }
}
